﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.MBSM.DBUtility;
using HZ.MBSM.BLL;
public partial class Company_Company_PSLX : System.Web.UI.Page
{
    private string _accountid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        { 
              HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
              if (_Account != null)
              {
                  _accountid = _Account.AccountId.ToString();
                  if (!Page.IsPostBack)
                  {
                      int _intisLX = 0;
                      int _checkstatus = 0;
                      Db db = new Db();
                      string strSql = "select isLX,isnull(checkstatus,0) as checkstatus from company where Accountid='" + _Account.AccountId.ToString() + "'";
                      System.Data.IDataReader dr;
                      dr = db.DataReader(strSql);
                      while (dr.Read())
                      {
                          _intisLX = SysFun.ToInt(dr["isLX"].ToString());
                          _checkstatus=SysFun.ToInt(dr["checkstatus"].ToString());
                      }
                      dr.Close();
                      dr.Dispose();
                      db.Close();
                      if (_intisLX == 1)
                      {
                          RadioButtonList1.SelectedIndex = 0;
                          Show();
                      }
                      else
                      {
                          RadioButtonList1.SelectedIndex = 1;
                          tabData.Visible = false;
                      }
                      if (_checkstatus.Equals(1) || _checkstatus.Equals(3))
                      {
                          panel1.Enabled = false;
                      }
                      else
                      {
                          panel1.Enabled = true;
                      }

                  }
              }
        }
    }
    // 更改；
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedIndex == 0)
        {
            tabData.Visible = true;
            Show();
        }
        else
        {
            tabData.Visible = false;
        }
    }
    //显示企业信息
    private void Show()
    {
        tabData.Visible = true;
        DataTable dt = Company.GetCompanyKX(_accountid);
        if (dt != null && dt.Rows.Count > 0)
        { 
            txtRegistermeneymark.Text = dt.Rows[0]["Registermeneymark"].ToString().Trim();
         
            txtPS.Text = dt.Rows[0]["hospitalPSnumber"].ToString().Trim();
           
            txtcompanyParDuty.Text = dt.Rows[0]["companyParDuty"].ToString().Trim();
          
            txtStorageArea.Text = dt.Rows[0]["StorageArea"].ToString().Trim();
          
            
            if (dt.Rows[0]["breachoflaw"].ToString() == "0" || dt.Rows[0]["breachoflaw"].ToString().Trim() == "")
            { RadioButtonList2.SelectedIndex = 1; }
            else
            { RadioButtonList2.SelectedIndex = 0; }
        }
        dt.Dispose();

    }
    ///保存
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedIndex == 0) //参与
        {
            HZ.MBSM.Model.Company com = new HZ.MBSM.Model.Company();
            com.Registermeneymark = txtRegistermeneymark.Text.Trim();
            com.hospitalPSnumber = txtPS.Text.Trim();
            com.companyParDuty = txtcompanyParDuty.Text.Trim();
            com.StorageArea = txtStorageArea.Text.Trim();
            com.breachoflaw = RadioButtonList2.SelectedValue;
            com.AccountId = Convert.ToInt64(_accountid);
           if( Company.UpdatcompanLX(com,1))
                Response.Write("<script language=JavaScript>alert('修改成功！');</script>");
           else
               Response.Write("<script language=JavaScript>alert('修改失败，请重新保存！');</script>");
        }
        else  //不参与
        {
            HZ.MBSM.Model.Company com = new HZ.MBSM.Model.Company();
            com.AccountId = Convert.ToInt64(_accountid);
            if (Company.UpdatcompanLX(com, 0))
                Response.Write("<script language=JavaScript>alert('修改成功！');</script>");
            else
                Response.Write("<script language=JavaScript>alert('修改失败，请重新保存！');</script>");
        }
    }

    #region IPageDescribe 成员


    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            return _AccountType;
        }
    }
    #endregion
   
}
